package com.woniuxy.his.service.impl;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.woniuxy.his.controller.form.AddImageCheckForm;
import com.woniuxy.his.entity.CheckDetail;
import com.woniuxy.his.entity.ImageCheck;
import com.woniuxy.his.mapper.CheckDetailMapper;
import com.woniuxy.his.mapper.ImageCheckMapper;
import com.woniuxy.his.service.IImageCheckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * <p>
 * 影像表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-28
 */
@Service
@Slf4j
public class ImageCheckServiceImpl extends ServiceImpl<ImageCheckMapper, ImageCheck> implements IImageCheckService {
    //生成影像检查结果
    @Resource
    private ImageCheckMapper imageCheckMapper;

    //修改结果生成成功后修改检查详情表中的 是否检查 字段属性为yse
    @Resource
    private CheckDetailMapper checkDetailMapper;

    @Override
    public boolean inageGenerateResults(AddImageCheckForm addImageCheckForm) {

        //将前端传入的数据赋值给实体类
        ImageCheck imageCheck = new ImageCheck();
        BeanUtils.copyProperties(addImageCheckForm, imageCheck);

        Integer insertDB = imageCheckMapper.insert(imageCheck);

        //判断是否新增成功
        if (insertDB !=null) {
            //生成检查结果表单成功
            //修改检查详情表中的 是否已检查 字段为yes
            //获取当前生成报告检查详情表ID
            Integer checkDetailId = addImageCheckForm.getCheckDetailId();
            //修改根据id修改 是否已检查 字段为yse
            UpdateWrapper<CheckDetail> wrapper = new UpdateWrapper<>();
            //修改字段和对应的值
            wrapper.set("ischecked", "yes");
            //条件字段和对应的值
            wrapper.eq("check_detail_id", checkDetailId);
            //调用方法修改
            Integer updateDB = checkDetailMapper.update(null, wrapper);
            //判断修改是否成功
            if (updateDB != null) {
                //修改成功则返回true
                return true;
            }
        }
        //新增或者修改失败则返回false
        return false;
    }
}
